//人员
function getUserManagePanel(t) {return new CMS.UserManagePanel(t)};
CMS.UserManageSearhPanel = function() {
	var serachItems = [
		getField({width:140,fieldLabel:'姓名',name:'name'}),getField({width:140,fieldLabel:'邮箱',name:'email'}),
		createNormlCommon(140 , gender_data , '性别' , '' , false, 'gender'),creDate({fieldLabel:'出生日期',name:'birthday'}),
		getField({width:140,fieldLabel:'证件号码',name:'idCard'}),getField({width:140,fieldLabel:'部门名',name:'deptName'})
	];
	CMS.UserManageSearhPanel.superclass.constructor.call(this, {
		region:'north',frame:true,height:100,xtype:"form",
		layout:"column",labelWidth:65,split:true,
        defaults:{
            columnWidth:0.28,layout:"form",hideLabels:true,border:false,bodyStyle:"padding:2px"
        },
        items:[{
            defaults:{xtype:"fieldset",layout:"form",anchor:"100%",autoHeight:true},
            items:[{
                autoHeight:true,defaults:{anchor:"-10"},
                items:[serachItems[0],serachItems[1]]
            }]
        },{
            defaults:{xtype:"fieldset",layout:"form",anchor:"100%",autoHeight:true},
            items:[{
                autoHeight:true,defaults:{anchor:"-10"},
                items:[serachItems[2],serachItems[3]]
            }]
        },{
            defaults:{xtype:"fieldset",layout:"form",anchor:"100%",autoHeight:true},
            items:[{
                autoHeight:true,defaults:{anchor:"-10"},
                items:[serachItems[4],serachItems[5]]
            }]
        },{
            columnWidth:0.15,height:80,layout:"form",buttons:[{text:'查询' ,iconCls:'searchIcon2',
            	handler:function() {USER_MANAGER_CONTENT_PANEL.refresh()}},
            {text:'新增',iconCls:'add',handler:function() {USER_MANAGER_CONTENT_PANEL.editInfo(1)}}]
        }]
	});
	this.getItems = function() {
		return serachItems;
	};
};
Ext.extend(CMS.UserManageSearhPanel, Ext.Panel);
var USER_MANAGER_CONTENT_PANEL;
CMS.UserManageContentPanel = function(searchPanel) {
	USER_MANAGER_CONTENT_PANEL = this;
	var objArr = converArr([
		{name:"id",hidden:true} , {name:'name' , width:140 , sortable:true , header:'用户'},
		//{name:'professional',hidden:true},
		{name:'email' , width:140 , sortable:true , header:'email'} ,{name:'idCard',hidden:true},
	    {name:'tel' , width:120 , header:'手机号码'},{name:'tel2' , hidden:true} , {name:'mobile' , width:120 , header:'座机'},
	    {name:'gender',hidden:true},{name:'loginName',hidden:true},{name:'roleId',hidden:true},{name:'deptId',hidden:true},
	    {name:'userContent',hidden:true},{name:'certificate',hidden:true},{name:'userDesc',hidden:true},
		{name:'genderStr' , width:120, header:'性别'} , {name:'birthDay' , width:120 , header:'出生日期'},
		{name:'deptName' , width:120 , header:'部门'} ,{name:'id',header:'操作',width:220, renderer:function(v,c,row) {
			var data = row.data;
			var ret =  '<a href="javascript:USER_MANAGER_CONTENT_PANEL.editInfo(2)">编辑</a> ' +
				   '<a href="javascript:USER_MANAGER_CONTENT_PANEL.grantRole()">授予角色</a> ' +
				   '<a href="javascript:USER_MANAGER_CONTENT_PANEL.resetUserPassword()">设置密码</a>';
			if(data['name']!="Admin")
				ret +=' <a href="javascript:USER_MANAGER_CONTENT_PANEL.deleteRow()">删除</a> ';   
			return ret;
		}}
	] , true);
	var ds = getPageDs(sys_base_url + 'getUsers' , 'id' , objArr);
	var pageBar = getPageBBar(20 , ds);
	CMS.UserManageContentPanel.superclass.constructor.call(this, {
		region:'center',store:ds,view:getGridView('没有找到数据'),
		columns:objArr.columns,sm:getRowModel(),bbar:pageBar
	});
	this.refresh = function() {
       ds.load({params:{start:0,limit:pageBar.pageSize}});
    };
    registPageDsParams(ds , searchPanel.getItems() , USER_MANAGER_CONTENT_PANEL.refresh);
    USER_MANAGER_CONTENT_PANEL.refresh();
    
    //编辑
    this.editInfo = function(type) {
    	var dWidth = 440;
    	var items = [
    		getHidden({name:'id',allowNull:true}),
    		getField({width:dWidth,name:'name',fieldLabel:'姓名'}) ,
    		getField({width:dWidth,name:'idCard',fieldLabel:'身份证'}),
    		createNormlCommon(dWidth , gender_data , '性别' , '' , false, 'gender'),
    		//createLocalCommonByData({fieldLabel:'专业',allowNull:true,width:dWidth,editable:false,name:'professional',emptyText:'请选择...'},professional),
    		//createProxyComm2({width:dWidth,emptyText:'请选择...',name:'professional',fieldLabel:'专业'},{url:sys_base_url + 'getProfessionals'}),
    		getField({width:dWidth,name:'loginName',fieldLabel:'登录名'}),
    		getField({width:dWidth,name:'password',inputType:"password",fieldLabel:'密码',notEdit:true}),
    		getField({width:dWidth,name:'email',fieldLabel:'email'}),
    		getField({width:dWidth,name:'tel',fieldLabel:'手机号'}),
    		getField({width:dWidth,name:'tel2',fieldLabel:'备用手机',allowNull:true}),
    		getField({width:dWidth,name:'mobile',fieldLabel:'电话'}),
    		creDate({fieldLabel:'出生日期',name:'birthDay',width:dWidth}),
    		createProxyComm2({width:dWidth,emptyText:'请选择...',name:'deptId',fieldLabel:'部门'},{url:sys_base_url + 'getDepartmentKV'}),
    		getArea({width:dWidth + 60,height:60,name:'userContent',fieldLabel:'个人履历',allowNull:true}),
    		getArea({width:dWidth + 60,height:60,name:'certificate',fieldLabel:'证书',allowNull:true}),
    		getArea({width:dWidth + 60,height:60,name:'userDesc',fieldLabel:'补充说明',allowNull:true})
    	];
    	pubEditRow(type ,items , USER_MANAGER_CONTENT_PANEL , '用户' , 520 , 800 , sys_base_url + 'saveUser' , USER_MANAGER_CONTENT_PANEL.refresh);
    };
    //删除
    this.deleteRow = function() {
    	pubDeleteRow(USER_MANAGER_CONTENT_PANEL , 'name' , '用户' , sys_base_url + 'saveUser' , ds , USER_MANAGER_CONTENT_PANEL.refresh);
    };
    this.resetUserPassword = function() {
    	var row = USER_MANAGER_CONTENT_PANEL.getSelectionModel().getSelected().data;
    	var password = getField({name:'password',inputType:'password',fieldLabel:'密码',width:200});
    	var form = getMyEmptyForm([password]);
    	var win = new CMS.Window({
    		items:[form],width:400,height:120,maximizable:false,
    		title:'给员工：【' + row['name'] + '】设置密码',
    		buttons:[{
    			text:'确定' , handler:function() {
    				if(!password.getValue()) return showTip('提示' , '密码不能为空。');
    		    	ajax({
    		    		url:sys_base_url + 'resetPasswordByAdmin',
    		    		params:{id:row['id'],password:password.getValue()},
    		    		success:function(resp) {
    		    			ajaxSuc(resp , USER_MANAGER_CONTENT_PANEL.refresh , null , win);
    		    		}
    		    	});
    			}
    		}]
    	});
    	
    };
    //授予角色
    this.grantRole = function() {
    	var userId = USER_MANAGER_CONTENT_PANEL.getSelectionModel().getSelected().data['id'];
    	var checkPanel = getTempCheckProxy(
    		{url:sys_base_url + 'getRoleByUser?type=1&id=' + userId,autoLoad:true},
    		{url:sys_base_url + 'getRoleByUser?type=2&id=' + userId,autoLoad:true},
    		400,
    		[
    			{name:'id',hidden:true},
    			{name:'name',width:120,header:'角色名'},
    			{name:'menuNums',width:60,header:'菜单数'},
    			{name:'responsible',width:200,header:'职责'}
    		],'备选角色' , '已选角色' , getBt('请选择角色') , function() {
    			var checkRoles = [] ,index = 0;
    			forEachDs(checkPanel.ds2 , function(row) {
    				checkRoles[index++] = row['id'];
    			});
    			ajax({
    				url:sys_base_url + "saveUserRoles",
    				params:{id:userId,roles:checkRoles},
    				success:function(resp) {
    					ajaxSuc(resp);
    					checkPanel.win.close();
    				}
    			})
    		}
    	);
    };
};
Ext.extend(CMS.UserManageContentPanel, Ext.grid.GridPanel);

CMS.UserManagePanel = function(title) {
	var searchPanel = new CMS.UserManageSearhPanel();
	var contentPanel = new CMS.UserManageContentPanel(searchPanel);
	CMS.UserManagePanel.superclass.constructor.call(this, {
		title:title,layout:'border',
		id:'user_manager_panel',
		items:[searchPanel , contentPanel]
	});
};
Ext.extend(CMS.UserManagePanel, Ext.Panel);

//部门
function getDeptManagePanel(t) {return new CMS.DeptManagePanel(t)};
var DEPT_MANAGER_PANEL;
var dept_names_config_list = [{name:'id',cname:'部门ID'} , {name:'text',cname:'部门名'} , {name:'deptFullName',cname:'部门全名'} ,
		{name:'deptResponsible' , cname:'部门职责'} , {name:'deptDesc' , cname:'描述'} , {name:'deptCreateDate' , cname:'部门创建日期'} ,
		{name:'createDate',cname:'内容创建时间'} , {name:'chgDate' , cname:'最后被修改时间'}
		/*, {name:'deptMgrName' , cname:'部门领导'}*/];
CMS.DeptManagePanel = function(title) {
	var content = new CMS.PubContent('部门详情' , dept_names_config_list , 'dept_tree_content');
	var deptTree = new CMS.DeptTree(content);
	DEPT_MANAGER_PANEL = this;
	CMS.DeptManagePanel.superclass.constructor.call(this, {
		title:title,layout:'border',items:[deptTree , content]
	});
};
Ext.extend(CMS.DeptManagePanel, Ext.Panel);

CMS.DeptTree = function(deptContent) {
	var treePanel = this;
	var rootNode = new Ext.tree.AsyncTreeNode({text:'部门列表',expanded:true});
	CMS.RoleMenus.superclass.constructor.call(this, {
		title:'组织架构',region:'west',width:260,split:true,collapsible:true,
		autoScroll:true,animate:true,enableDD:false,collapseMode: 'mini',
		containerScroll: false,rootVisible: true,iconCls:'userIcon',checkModel: 'cascade',
		loader: new Ext.tree.TreeLoader({
            dataUrl :sys_base_url + 'getDepartments'
        }),
        root: rootNode,
        listeners:{
       		'click':function(node) {
               deptContent.setContent(node);
           }
       }
	});
	var tempExpandArray = {} , nowTempId = null;
	treePanel.on("load" , function(node) {
		if(isNaN(node.attributes['id'])) {
			node.expand(false , true , expandCallBack);
		}
	});
	
	var expandCallBack = function(node) {
		if(node.hasChildNodes()) {
			forEach(node.childNodes , function(nd) {
				if(nd.attributes['levelId'] == 1 || tempExpandArray['k_' + nd.attributes['id']]) {
					nd.expand(false , true , expandCallBack);
					if(nowTempId == nd.attributes['id']) deptContent.setContent(nd);
				}
			});
		}
	};
	treePanel.on('contextmenu' , function(node , e) {
		var menuList = new Ext.menu.Menu({
			items:[{
				text:'添加同级部门',iconCls:'add',handler:function() {treePanel.addNewDept(node , 3);}
			},{
				text:'添加子部门',iconCls:'add4',handler:function() {treePanel.addNewDept(node , 1);}
			},{
				text:'编辑部门信息',iconCls:'editIcon2',handler:function() {treePanel.addNewDept(node , 2);}
			},{
				text:'删除部门',iconCls:'deleteIcon2',handler:function() {treePanel.deleteDept(node , 4)}
			},{
				text:'移动部门',iconCls:'moveIcon',handler:function() {treePanel.moveNode(node , 5)}
			}/*,{
				text:'设置部门领导',iconCls:'moveIcon',handler:function() {treePanel.setMgr(node, 6)}
			}*/]
		});
		menuList.showAt(e.getXY());
	});
	//type=1添加子部门,type=3添加同级部门,type=2编辑
	this.addNewDept = function(node , type) {
		var title = '';
		if(type == 1) title = '为[' + getBt(node['text']) + ']添加子部门';
		else if(type == 3) title = '为[' + getBt(node['text']) + ']添加同级部门';
		else title = '编辑[' + getBt(node['text']) + ']';
		var dWidth = 340;
		var commonBox = createProxyComm2({width:dWidth,emptyText:'类型',fieldLabel:'部门类型',name:'deptType'} , 
			{url:sys_base_url + 'getDeptTypes'});
		var items = [
			getField({width:dWidth,name:'deptName',fieldLabel:'部门名',allowNull:false}),
			commonBox,
			//creDate({width:dWidth,name:'deptCreateDate',fieldLabel:'部门创建日期',allowNull:false}),
			getArea({width:dWidth + 80 ,height:120, name:'deptResponsible' , fieldLabel:'部门职责',allowNull:true}),
			getArea({width:dWidth + 80 ,height:120, name:'deptDesc' , fieldLabel:'描述',allowNull:true})
		];
		if(type == 2) {
			forEach(items , function(item) {
				//alert(item.name + ":" + node.attributes[item.name]);
	    		if(item.store && item.store.url) {
	    			item.store.on('load' , function() {item.setValue(node.attributes[item.name])});
	    		}else {
	    			item.setValue(node.attributes[item.name]);
	    		}
	    	});
		}
		var form = getMyEmptyForm(items);
    	var win = getEmptyPanel3([{
	    	text:'确定' , handler:function() {
	    		var params = checkObjs(items , {id:node['id'] ,parentId:node.attributes['parentId'], type:type});
	    		if(!params) return;
	    		ajax({
	    			url:sys_base_url + 'saveDepartment',
	    			params:params,
	    			success:function(resp) {
	    				treePanel.pubAjaxCallBack(resp , win);
	    			}
	    		});
	    	}
	    }] , title , form , 380 , 650);
	};
	//删除
	this.deleteDept = function(node , type) {
		ajax({
			url:sys_base_url + 'hasChildDepartment?id=' + node['id'],
			success:function(resp) {
				if(resp.responseText == "0") {
					treePanel.deleteDo(node , type , 1);
				}else {
					treePanel.deleteChildConfirm(node , type);
				}
			}
		});
	};
	this.deleteChildConfirm = function(node , type) {
        var childConfirms = new Ext.form.RadioGroup({fieldLabel:'子节点处理',items:[
                getRadio('process_child' , 2 , '移动到上级部门' , true),getRadio2('process_child' , 3 , '级联删除')
        ]});
        var form = getMyEmptyForm([childConfirms]);
        var win2 = getEmptyPanel3([{
            text:'确定',handler:function() {
                treePanel.deleteDo(node , type , childConfirms.getValue().inputValue);
                win2.close();
            }
        }] , '节点：【' + node['text'] + '】包含有子部门，请选择子部门处理方法。' , form , 110 , 420);
    };
	this.deleteDo = function(node , type , delModel) {
		confirm('确定要删除部门:[' + node['text'] + ']吗？' , function(v) {
			if(v == 'yes') {
				ajax({
					url:sys_base_url + 'saveDepartment',
					params:{id:node['id'] , type:type , model:delModel},
					success:function(resp) {
						treePanel.pubAjaxCallBack(resp , null);
			    	}
				});
			}
		});
	};
	//移动部门
	this.moveNode = function(node , type) {
		var moveType = createNormlCommon(300,[['1' , '之前'],['2','之后'] , ['3' ,'子部门']] , '相对位置' , '2' ,false, 'common' + getTempNum());
		var compMenu = createProxyComm2({width:300,emptyText:'部门列表',fieldLabel:'相对位置'} , {url:sys_base_url + 'getCheckDeparentMents'});
		var form = getMyEmptyForm([compMenu , moveType]);
		var win = getEmptyPanel3([{
			text:'确定' , handler:function() {
				if(!compMenu.getValue()) return showTip2('提示' , '请先选择部门移动的相对位置。' , 2);
				if(node['id'] == compMenu.getValue()) return showTip2('提示' , '相对位置不能是部门本身。' , 2);
				ajax({
					url:sys_base_url + 'saveDepartment',
					params:{id:node['id'] , compId:compMenu.getValue() , moveType:moveType.getValue() , type:type},
					success:function(resp) {
						treePanel.pubAjaxCallBack(resp , win);
					}
				});
			}
		}] , '移动部门：【' + node['text'] + '】，请选择目标位置' , form , 130 , 600);
	};
	// 设置部门经理
	this.setMgr = function(node, type){
		var userList = createProxyComm2({width:300,emptyText:'部门员工列表',fieldLabel:'部门员工列表'} , {url:sys_base_url + 'getUsersByDept?deptId='+node['id']});
		var form = getMyEmptyForm([userList]);
		var win = getEmptyPanel3([{
			text:'确定' , handler:function() {
				ajax({
					url:sys_base_url + 'saveDepartment',
					params:{id:node['id'] , deptMgr:userList.getValue(), type:type},
					success:function(resp) {
						treePanel.pubAjaxCallBack(resp , win);
					}
				});
			}
		}] , '设置部门：【' + node['text'] + '】，请选择领导' , form , 100 , 600);
	};
	//刷新树
	this.refresh = function(allparentId) {
		allparentId = allparentId.substring(1 , allparentId.length - 1);
		var ids = allparentId.split("}{");
		tempExpandArray = {};
        forEach(ids , function(node) {
           tempExpandArray["k_" + node] = "1";
        });
        nowTempId = ids[ids.length - 1];
        treePanel.getLoader().load(rootNode , function() {
           rootNode.expand(false , true , expandCallBack);
        });
	};
	//公共ajax回调
	this.pubAjaxCallBack = function(resp , win) {
		var json = getJson(resp.responseText);
		if(json['status'] == '1') {
			showTip('提示' , json['msg']);
		    treePanel.refresh(json['msg']);
		    if(win) win.close();
		}else {
		    showTip('提示' , json['msg']);
		}
	};
};
Ext.extend(CMS.DeptTree, Ext.tree.TreePanel);

//角色
function getRoleManagePanel(t) {return new CMS.RoleManagePanel(t)};
var ROLE_MANAGE_PANEL;
var menu_names_config_list = [{name:'id',cname:'菜单ID'},{name:'parentId',cname:'父节点ID'},{name:'text',cname:'菜单名称'},{name:'levelId',cname:'层次'},
    {name:'allParentId',cname:'所有父节点'},{name:'menuDesc',cname:'描述'},{name:'busiKey',cname:'业务关键字（用于区分控件复用）'},
    {name:'sysName',cname:'系统英文名(一级菜单使用)',comp:'levelId',vl:1},{name:'orderId',cname:'顺序号'},{name:'jsFiles',cname:'JS文件加载(一级菜单使用)',comp:'levelId',vl:1},
    {name:'clickType',cname:'触发类型',func:getClickType},{name:'url',cname:'连接路径',comp:'clickType',vl:'2'},
    {name:'target',cname:'目标',func:getTargetName,comp:'clickType',vl:'2'},{name:'functionName',cname:'JS方法名',comp:'clickType',vl:'1'},
    {name:'objectId',cname:'功能区对象ID',comp:'clickType',vl:'1'},{name:'mutiObject',cname:'功能区是否复用',func:getnNormalConvName,comp:'clickType',vl:'1'},
    {name:'refresh',cname:'功能切换是否调用refresh方法',func:getnNormalConvName,comp:'clickType',vl:'1'},
    {name:'menuType',cname:'菜单可见性',func:getMenuTypeKv},{name:'expandChild',cname:'展开子节点',func:getnNormalConvName}
];
CMS.RoleManagePanel = function(title) {
	ROLE_MANAGE_PANEL = this;
	var objArr = converArr([
		{name:"id",hidden:true} , {name:'name' , width:140 , sortable:true , header:'角色名'},
		{name:'responsible' , width:200 , sortable:true , header:'职责描述'} ,
	    {name:'menuNums' , width:120 , header:'权限菜单数'} , {name:'roleKey',hidden:true},
		{name:'members' , width:120, header:'角色成员数'} , {name:'createDate' , width:120 , header:'创建日期'},
		{name:'chgDate' , width:120 , header:'最后修改日期'},{name:'id',header:'操作',width:120, renderer:function(v) {
			/*'<a href="javascript:ROLE_MANAGE_PANEL.editInfo(' + pub_edit_option + ')">编辑</a> ' 
			+  '<a href="javascript:ROLE_MANAGE_PANEL.deleteRow()">删除</a> '
			+ */
			return '<a href="javascript:ROLE_MANAGE_PANEL.grantPriv()">授权</a>';
		}}
	] , true);
	var roleNameSearch = getField({width:190,name:'name'});
	var responsibleSearch = getField({width:190,name:'responsible'});
	var ds = getPageDs(sys_base_url + 'getRoles' , 'id' , objArr);
	var pageBar = getPageBBar(20 , ds);
	CMS.RoleManagePanel.superclass.constructor.call(this, {
		title:title,store:ds,view:getGridView('没有找到数据'),
		columns:objArr.columns,sm:getRowModel(),bbar:pageBar,
		id:'role_manager_panel',tbar:['-',{
			text:'角色名：'
		},roleNameSearch ,'-', {
			text:'职责:'
		},responsibleSearch,'-',{
			text:'查询',iconCls:'searchIcon2',handler:function() {ROLE_MANAGE_PANEL.refresh()}
		}/*,'-' ,{
			text:'新增',iconCls:'add',handler:function() {
				ROLE_MANAGE_PANEL.editInfo(pub_add_option);
			}
		},'-'*/]
	});
	this.refresh = function() {
       ds.load({params:{start:0,limit:pageBar.pageSize}});
    };
    registPageDsParams(ds , [roleNameSearch , responsibleSearch] , ROLE_MANAGE_PANEL.refresh);
    ROLE_MANAGE_PANEL.refresh();
    //编辑
    this.editInfo = function(type) {
    	var dWidth = 340;
    	var items = [
    		getHidden({name:'id',allowNull:true}),
    		getField({width:dWidth,name:'name',fieldLabel:'角色名'}) ,
    		/*createProxyComm2({width:dWidth,emptyText:'请选择...',name:'roleKey',fieldLabel:'角色类型'},{url:sys_base_url + 'getRoleTypes'}),*/
    		getArea({width:dWidth,height:60,name:'responsible',fieldLabel:'职责描述'})
    	];
    	pubEditRow(type ,items , ROLE_MANAGE_PANEL , '角色' , 200 , 600 , sys_base_url + 'saveRole', ROLE_MANAGE_PANEL.refresh);
    };
    
    //删除
    this.deleteRow = function() {
    	pubDeleteRow(ROLE_MANAGE_PANEL , 'name' , '角色' , sys_base_url + 'saveRole' , ds , ROLE_MANAGE_PANEL.refresh);
    };
    //授权
    this.grantPriv = function() {
    	var roleNode = ROLE_MANAGE_PANEL.getSelectionModel().getSelected().data;
    	var menuContent = new CMS.PubContent('菜单详情' , menu_names_config_list , "menu_content_panel");
    	var roleMenu = new CMS.RoleMenus(menuContent , roleNode['id']);
    	var win = new Ext.Window({
    		layout:'border',items:[menuContent , roleMenu],height:520 , width:850,
    		title:'请为角色：[' + getBt(roleNode['name']) + ']授予相应的菜单权限！',buttonAlign:'center',buttons:[{
	       		text:'保存',handler:function() {
	       			var checkedNodes = roleMenu.getChecked();
	       			var menuIds = [] , index = 0;
	       			Ext.each(checkedNodes , function() {
	                   var nd = this;
	                   if(nd.attributes['leaf']) {
	                       menuIds[index++] = nd.attributes['id'];
	                   }
	               });
	               ajax({
	                   url:sys_base_url + 'saveRoleMenus',
	                   params:{ids:menuIds,roleId:roleNode['id']},
	                   success:function(resp) {ajaxSuc(resp,ROLE_MANAGE_PANEL.refresh);win.close();}
	               });
	       		}
	       	},{
	       		text:'取消',handler:function() {win.close()}
	       	}]
    	});
    	win.show();
    };
};
Ext.extend(CMS.RoleManagePanel, Ext.grid.GridPanel);

CMS.RoleMenus = function(menuContent , id) {
	var treePanel = this;
	var rootNode = new Ext.tree.AsyncTreeNode({expanded:true});
	CMS.RoleMenus.superclass.constructor.call(this, {
	   title:'菜单列表',region:'west',width:260,split:true,collapsible:true,
       autoScroll:true,animate:true,enableDD:false,collapseMode: 'mini',
       containerScroll: false,rootVisible: false,iconCls:'userIcon',checkModel: 'cascade',
       loader: new Ext.tree.TreeLoader({
            dataUrl :sys_base_url + 'getAllRoleMenus?roleId=' + id,
            baseAttrs: {uiProvider: Ext.tree.TreeCheckNodeUI}
       }),
       root: rootNode,
       listeners:{
       		'click':function(node) {
               menuContent.setContent(node);
           }
       }
	});
	
};
Ext.extend(CMS.RoleMenus, Ext.tree.TreePanel);

CMS.PubContent = function(title,config_list,baseId) {
	var content_id = baseId + getTempNum();
	CMS.PubContent.superclass.constructor.call(this, {
        title:title,region:'center',html:'<div id="' + content_id + '"></div>',
        autoScroll:true
    });
    this.setContent = function(node) {
    	var htmlCode = '<table class="table" style="table-layout:fixed;word-break: break-all;word-wrap:break-word;" width="100%"><tbody><tr><td class="plat_table-row-over" width="20%">名称</td><td class="plat_table-row-over">内容</td></tr>';
    	var index = 1;
        forEach(config_list , function(config) {
            if(config['comp'] && config['vl']) {
                if(node.attributes[config['comp']] != config['vl']) return;
            }
            var classNode = getTabDetailRowCss(index++);
            var name = config['name'];
            var value = node.attributes[name];
            if(config['func']) {
                value = config['func'].call(this , value);
            }
            var cname = config['cname'];
            htmlCode += '<tr><td class="' + classNode[0] + '">' + cname + ' : <td class="' + classNode[1] + '">' + value + '</td></tr>';
        });
        Ext.get(content_id).dom.innerHTML = htmlCode + '</tbody></table>';
    };
};
Ext.extend(CMS.PubContent, Ext.Panel);
function getUserPassManagePanel(t) {return new CMS.UserPassManagerPanel(t)};
CMS.UserPassManagerPanel = function(title) {
	var oldPass = getField({width:240,fieldLabel:'旧密码',inputType:'password',allowBlank:false,blankText:'旧密码不能为空！'});
	var newPass = getField({width:240,fieldLabel:'新密码',inputType:'password',allowBlank:false,blankText:'新密码不能为空！'});
	var newPassConfirm = getField({width:240,fieldLabel:'确认新密码',inputType:'password',allowBlank:false,blankText:'确认密码不能为空！'});
	var form = getMyEmptyForm([oldPass,newPass,newPassConfirm] , 90);
	form.frame = true;
	CMS.UserPassManagerPanel.superclass.constructor.call(this , {
		title:title,id:'user_password_manager',frame:true
	});
	var win = new Ext.Window({
		shadow:true,shadowOffset:10,layout:'border',items:form,
		height:200,width:400,title:'修改密码',closable:true,buttonAlign:'center',
		buttons:[{
			text:'确定',handler:function() {
				if(!form.form.isValid()) return;
				ajax({
					url:sys_base_url + 'resetMyPassword',
					params:{oldPass:oldPass.getValue() , newPass:newPass.getValue() , newPassConfirm:newPassConfirm.getValue()},
					success:function(resp) {
						var json = getJson(resp.responseText);
						showTip('提示' , json['msg']);
						form.form.reset();
					}
				});
			}
		},{
			text:'重置',handler:function() {form.form.reset();}
		}]
	});
	win.show();
	this.on('beforedestroy' , function() {
		if(win) win.close();
	});
};
Ext.extend(CMS.UserPassManagerPanel, Ext.Panel);


